export const useCustomFetch = async <T>(
  url: string,
  options: Record<string, any> = {}
) => {
  const token = useCookie('token')
  const { data, error, status } = await useFetch<T>(url, {
    ...options,
    watch: false, // https://github.com/nuxt/nuxt/issues/15741#issuecomment-1622652063
    headers: {
      Authorization: `Bearer ${token.value}`,
    },
  })
  return { data, error, status }
}

export const useCustomDelete = async <T>(url: string, options = {}) => {
  return useCustomFetch<T>(url, { ...options, method: 'delete' })
}

export const useCustomGet = async <T>(
  url: string,
  options: { params?: Record<string, any> } = {}
) => {
  return useCustomFetch<T>(url, { ...options, method: 'get' })
}

export const useCustomPost = async <T>(url: string, options = {}) => {
  return useCustomFetch<T>(url, { ...options, method: 'post' })
}

export const useCustomPut = async <T>(url: string, options = {}) => {
  return useCustomFetch<T>(url, { ...options, method: 'put' })
}
